home *** CD-ROM | disk | FTP | other *** search
/ Chip 1996 November / CHIP Kasım 1996.iso / prog / tw / tfw.5 / WHUTILS.SLT < prev    next >
Text File  |  1994-12-07  |  3KB  |  127 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  Do NOT compile this file.  It is included (#INCLUDE) in the WINHOST.SLT
  4. //  and WCONFIG.SLT files.  If you change it, simply save the changes and
  5. //  recompile those files.  They will compile this file as necessary.
  6. //
  7. //////////////////////////////////////////////////////////////////////////////
  8. //
  9. //  Functions common to the main HOST script and the script that maintains
  10. //  the configuration file
  11. //
  12. //////////////////////////////////////////////////////////////////////////////
  13.  
  14. // Get the directory in which we are going to store our stuff
  15.  
  16. get_our_dir () {
  17.     int length;
  18.   getRunPath(our_dir);
  19.   if (!our_dir)
  20. //      if (!getenv ("HOST2DIR", our_dir)) // environment variable there?
  21.       our_dir = _script_dir;
  22.  
  23.   // add a backslash on the end if necessary
  24.   strupper (our_dir);
  25.   length = strlen (our_dir);
  26.   if (length) --length;
  27.      if (subchr(our_dir, length) != '\')
  28.        strcat (our_dir, "\");
  29. }
  30.  
  31. //////////////////////////////////////////////////////////////////////////////
  32.  
  33. read_host_config_file() {
  34.  
  35.   str s[80];
  36.   int f, ret_val;
  37.  
  38.   s = our_dir;
  39.   strcat(s, "WINHOST.CNF");
  40.  
  41.   if (!(f = fopen(s, "r"))) {
  42.     printsc("Can't open ");
  43.     prints(s);
  44.     return -1;
  45.   }
  46.  
  47.   prints ("Reading configuration file ...");
  48.   ret_val = 1;
  49.  
  50.   // Read our download directory
  51.   if (fgets (s, 80, f) != -1) {
  52.     host_downloads = s;
  53.  
  54.     // Read our upload directory
  55.     if (fgets (s, 80, f) != -1) {
  56.       host_uploads = s;
  57.  
  58.       // Read direct connection flag
  59.       if (fgets (s, 80, f) != -1) {
  60.         direct_connect = (toupper(subchr(s, 0)) == 'D');
  61.  
  62.         // Read modem lock flag
  63.         if (fgets (s, 80, f) != -1) {
  64.           modem_lock = s;
  65.  
  66.           // Read closed-system flag
  67.           if (fgets (s, 80, f) != -1) {
  68.             closed_sys = (toupper (subchr (s, 0)) == 'C');
  69.           }
  70.  
  71.           // Error condition handling
  72.           else {
  73.             prints ("Error reading closed-system line!");
  74.             ret_val = -1;
  75.           }
  76.         }
  77.         else {
  78.           prints ("Error reading modem line!");
  79.           ret_val = -1;
  80.         }
  81.       }
  82.       else {
  83.         prints ("Error reading direct connect line!");
  84.         ret_val = -1;
  85.       }
  86.     }
  87.     else {
  88.       prints ("Error reading host upload directory line!");
  89.       ret_val = -1;
  90.     }
  91.   }
  92.   else {
  93.     prints ("Error reading host download directory line!");
  94.     ret_val = -1;
  95.   }
  96.  
  97.   fclose(f);
  98.   return (ret_val);
  99. }
  100.  
  101. //////////////////////////////////////////////////////////////////////////////
  102.  
  103. check_directory (str dirname) {
  104.  
  105.   str s[80];
  106.   int i, a;
  107.  
  108.   // first remove trailing slashes
  109.  
  110.   s = dirname;
  111.   i = strlen(s);
  112.   if (i > 0)
  113.     if (subchr(s, i - 1) == '\' || subchr(s, i - 1) == '/')
  114.       setchr(s, i - 1, 0);
  115.   if (s && !(strlen(s) == 2 && subchr(s, 1) == ':')) {
  116.     a = fileattr(s);
  117.     if (a == -1 || !(a & 16)) {
  118.       printsc (s);
  119.       prints (" does not exist.^M^J");
  120.       return 0;                  // not a directory or doesn't exist
  121.     }
  122.   }
  123.  
  124.   return 1;
  125.  
  126. }
  127.